#ifndef QUICKSORT_H
#define QUICKSORT_H

#include "sortbase.h"
#include <QEventLoop>
#include <QVariantAnimation>

class QuickSort : public SortBase
{
    Q_OBJECT
public:
    explicit QuickSort(QObject *parent = nullptr);

    // virtual function/interface for sort
    void sort(size_t num_of_elem, int interval) override;
    void stop() override;
    void draw(QPainter *painter, int width, int height) override;
    void skip() override;

private:
    void QSort(int low, int high);
    void QSwap(int from, int to);
    void wait(int ms);

private:
    QEventLoop loop;
    QVariantAnimation animation;
    int interval{1};

    // sort related
    int pivot_index{0};
    size_t pivot_value{0};
    int sortLow{0};
    int sortHigh{0};
    int currLow{0};
    int currHigh{0};

    int swapFrom{0};
    int swapTo{0};
    bool swapFlag{false};
};

#endif // QUICKSORT_H
